Yearly change

library(tidyverse)
## -- Attaching packages --------------------------------------- tidyverse 1.3.2 --
## v ggplot2 3.3.6      v purrr   0.3.4 
## v tibble  3.1.8      v dplyr   1.0.10
## v tidyr   1.2.1      v stringr 1.4.1 
## v readr   2.1.2      v forcats 0.5.2 
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
library(dplyr)
crimes <- read_csv("E:/WISC/Fall 2022/STAT 679/project/archive/Crimes_With_Dates_Cleaned.csv")
## New names:
## * `` -> `...1`
## Warning: One or more parsing issues, see `problems()` for details
## Rows: 306094 Columns: 36
## -- Column specification --------------------------------------------------------
## Delimiter: ","
## chr (25): Dispatch Date / Time, NIBRS Code, Crime Name1, Crime Name2, Crime ...
## dbl (10): ...1, Incident ID, Offence Code, CR Number, Victims, Zip Code, Add...
## lgl  (1): Committed_At_Morning
## 
## i Use `spec()` to retrieve the full column specification for this data.
## i Specify the column types or set `show_col_types = FALSE` to quiet this message.
data1 <- data.frame(crimes[,32],crimes[,8:10])

data2 <- data1 %>%
  group_by(Crime.Name1) %>%
  count(Year)

ggplot(data2) +
  geom_line(aes(Year, n, col = Crime.Name1))

library(plotly)
## 
## 载入程辑包:'plotly'
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## The following object is masked from 'package:stats':
## 
##     filter
## The following object is masked from 'package:graphics':
## 
##     layout
fig <- plot_ly(data2, x = ~Year, y = ~n, type = 'scatter', mode = 'lines', color = ~Crime.Name1)
fig

To visualize the change in the number of criminal cases year by year, we decided to use a line graph to represent the change in the number of crimes per year. This can more directly observe the increase or decrease in the number of crimes and can also predict the number of crimes in the future.

Here, we used an interactive visualization, which you can zoom into selected area by brushing or choose to show the exact data by moving your mouse over the lines. To implement this, we first grouped the dataset by crime type, and counted how many times each crime is committed by each year. Then, we plotted Year against the counted numbers of crime cases in a line graph and colored each crime type for more intuitive observations to users.

For critical evaluation, if we implement a stacked area plot, some areas will be overlaid on another area, so we will not be able to see the exact value of this data. Therefore, we chose to use a line plot instead of a stacked area plot, even though the stacked area plots make it easier to tell how the totals at any timepoint breakdown across groups.